<?php
include_only();

$user_info = get_user_info();
$userid = $user_info['id'];

if(!empty($submit_comment) and $submit_comment=='yes' and check_comment_duplicate($video_id, $userid, $comment)=='no'){
write_video_comment($video_id, $userid, $comment);
}

//echo $video_id;

$all_comments = read_video_comments($video_id);

//print_r($all_comments);

$video_comments = "";

for ($i = 0; $i <= count($all_comments)-1; $i++) {

    $video_comments = $video_comments . "
<table style='width:100%'>
<tr>
<td style='width:100%'>
".get_user_name($all_comments[$i]['id'])."
</td>
<td>
<!--//sk8sn0surf - Convert microtime to date and time-->
".date('h:i:s A m-d-Y ', $all_comments[$i]['time'])." 
</td>
</tr>
<tr>
<td colspan='2'>
".$all_comments[$i]['message']."
</td>
</tr>
</table>
<br>
";
}

if(empty($video_id)){$video_id = "";}

$video_comments = $video_comments . "
<form name='form_comments' method='post' action='index.php'>
<table style='width:100%'>
<tr>
<td colspan='2'>
<textarea name='comment' style='width:100%' rows='3' onkeypress='return imposeMaxLength(event, this, 255);'></textarea>
</td>
</tr>
<tr>
<td style='width:100%'>
<input type='submit' value='submit' />
</td>
<td>
<input type='text' name='letters_count' style='width:30px;' value='255'/>
<input type='hidden' name='page' value='video_player' />
<input type='hidden' name='video_id' value='".$video_id."' />
<input type='hidden' name='submit_comment' value='yes' />
</td>
</tr>
</table>
</form>

<script>
function imposeMaxLength(Event, Object, MaxLen)
{
		document.form_comments.letters_count.value = 255 - Object.value.length;
        return (Object.value.length <= MaxLen)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40))
}
</script>
";
?>